<template>
  <div>
    <el-dialog title="收入信息登记" :visible.sync="dialogFormVisible">
      <el-form :model="form"
        v-loading="fetchLoading"
        class="sectionForm"
        size="mini"
        element-loading-text="数据加载中,请耐心等待..."
        label-width="80px"
        label-position="right"
    >
        <el-row >
          <el-col :span="12">
            <el-form-item label="园地名称">
              <el-select v-model="form.gardenPlot" autocomplete="off" size="mini"  placeholder="园地名称" value-key="gardenId">
                <el-option v-for="item in gardenPlotList" 
                :key="item.value"
                :label="item.gardenName"
                :value="item"/>
              </el-select>
             </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="园地面积">
              <el-input v-model="form.gardenPlot.gardenArea" disabled autocomplete="off" size="mini"  placeholder="园地面积"></el-input>
             </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="种植品种">
              <el-input v-model="form.gardenPlot.gardenVar" disabled autocomplete="off" size="mini"  placeholder="种植品种"></el-input>
             </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="果树数量">
              <el-input v-model="form.gardenPlot.gardenSnum" disabled autocomplete="off" size="mini"  placeholder="果树数量"></el-input>
             </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="收入名称">
              <el-input v-model="form.incomeName" autocomplete="off" size="mini"  placeholder="收入名称"></el-input>
             </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收入金额">
              <el-input v-model="form.incomePrice" autocomplete="off" size="mini"  placeholder="收入金额"></el-input>
             </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="收入日期">
              <el-date-picker type="date" placeholder="选择日期" v-model="form.incomeDate" style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input type="textarea" v-model="form.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" v-if="type==='add'" @click="add">确认添加</el-button>
        <el-button type="primary" v-else @click="add">确认修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default{
  name:'add',
  props:{
    type:{
      type:String,
    }
  },
  data(){
    return {
      dialogFormVisible:false,
      fetchLoading: false,
      form: {
        gardenPlot: {
          gardenName: '',
          gardenArea: '',
          gardenVar: '',
          gardenSnum: '',
        },
        incomeName: '',
        incomePrice: '',
        incomeDate: '',
        remark: '',
      },
      gardenPlotList: [],
    }
  },
  async created(){
    let res=await this.$API.gardenInfo.getList({})
    if(res.code==200){
      this.gardenPlotList = res.data
      // console.log(this.gardenPlotList,5555)
    }
  },
  methods:{
    cancel(){
      this.dialogFormVisible = false
      Object.assign(this.$data.form, this.$options.data().form)
    },
    async add(){
      this.dialogFormVisible = false
      // this.$emit("save",)
      try{
        let res=await this.$API.revenueInfo.saveOrUpdate(this.form)
        if(res.code==200){
          this.$message({type:"success",message:this.type==="add"?"添加成功":"修改成功"})
          this.$parent.updatePageList()
          Object.assign(this.$data.form, this.$options.data().form)
        }
      }catch{
        this.$message({type:"error",message:this.type==="add"?"添加失败":"修改失败"})
      }
    }
  }
}
</script>

<style scoped>
</style>